#pragma once
#include<vector>
#include<deque>
namespace mutou {
	template <class T>
	struct greater
	{
		bool operator()(const T& a, const T& b)
		{
			return a > b;
		}
	};
	template<class T>
	struct less
	{
		bool operator()(const T& a, const T& b)
		{
			return a < b;
		}
	};
	template<class T>
	struct less<T*>
	{
		bool operator()(const T* const& p1, const T* const& p2)
		{
			return *p1 < *p2;
		}
	};
	template <class T, class container = vector<T>,class compare = less<T>>
	class priority_queue
	{
	public:
		priority_queue()
		{
		}
		template <class InputIterator>

		priority_queue(InputIterator first, InputIterator last)
		{
			while (first != last)
			{
				push(*first++);
			}
		}


		void push(const T& val)
		{
			_con.push_back(val);
			adjustup(_con.size() - 1);
		}
		void pop()
		{
			std::swap(_con[0], _con[_con.size() - 1]);
			_con.pop_back();
			adjustdown(0);
		}
		const T& top()const
		{
			return _con[0];
		}
		bool empty()const
		{
			return _con.empty();
		}
		size_t size()const
		{
			return _con.size();
		}
	private:
		container _con;
		compare cmp;
		void adjustup(size_t child)
		{
			size_t parents = (child - 1) / 2;
			while (child > 0)
			{
				//if (_con[child] > _con[parents])
				if(cmp(_con[parents],_con[child]))
				{
					std::swap(_con[child], _con[parents]);
					child = parents;
					parents = (child - 1) / 2;
				}
				else
				{
					break;
				}
			}

		}
		void adjustdown(size_t parents)
		{
			size_t child = parents * 2 + 1;
			while (child < _con.size())
			{
				//if (child + 1 < _con.size() && _con[child + 1] > _con[child])
				if (child + 1 < _con.size() &&cmp( _con[child ] , _con[child+1]))
				{
					child++;
				}
				//if (_con[child] > _con[parents])
				if(cmp(_con[parents],_con[child]))
				{
					std::swap(_con[child], _con[parents]);
					parents = child;
					child = parents * 2 + 1;
				}
				else {
					break;
				}
			}
		}
	};
}